<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="searchToggle">
        <!-- 搜索栏 -->
        <label class="el-form-item-label">名称</label>
        <el-input v-model="query.title" clearable placeholder="名称" style="width: 185px;" class="filter-item" @keyup.enter="fetchList" />
        <label class="el-form-item-label">分类id</label>
        <el-input v-model="query.categoryId" clearable placeholder="分类id" style="width: 185px;" class="filter-item" @keyup.enter="fetchList" />
        <label class="el-form-item-label">链接地址</label>
        <el-input v-model="query.link" clearable placeholder="链接地址" style="width: 185px;" class="filter-item" @keyup.enter="fetchList" />
        <el-date-picker
            v-model="query.createTime"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="datetimerange"
            range-separator="至"
            start-placeholder="createTime开始"
            end-placeholder="createTime结束"
            class="filter-item"
        />
        <rr-operation></rr-operation>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crud-operation></crud-operation>
    </div>
    <!--表格渲染-->
    <el-table height="100" row-key="id" ref="table" v-loading="tableLoading" :data="tableData" border style="width: 100%" @selection-change="selectionChangeHandler">
      <el-table-column type="selection" width="55" />
      <el-table-column prop="id" label="id" />
      <el-table-column prop="title" label="名称" />
      <el-table-column prop="categoryId" label="分类id" />
      <el-table-column prop="link" label="链接地址" />
      <el-table-column prop="status" label="状态：-1,删除；0，待审核；1，正常">
        <template v-slot="{row}">
          {{ dict.label.GeneralStatus[row.status] }}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="createTime" />
      <el-table-column prop="uni" label="uni" />
      <el-table-column v-permission="permission.edit.concat(permission.remove)" label="操作"
                       width="150px"
                       align="center">
        <template v-slot="{row}">
          <ud-operation :data="row"></ud-operation>
        </template>
      </el-table-column>
    </el-table>

    <!--分页组件-->
    <pagination/>

    <!--表单组件-->
      <el-dialog draggable :close-on-click-modal="false" v-model="dialog.visible"
                 :title="dialog.title" width="500px">
        <el-form ref="formRef" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="名称" prop="title">
            <el-input v-model="form.title" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="分类id">
            <el-input v-model="form.categoryId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="链接地址" prop="link">
            <el-input v-model="form.link" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="状态：-1,删除；0，待审核；1，正常">
            <el-select v-model="form.status" filterable placeholder="请选择">
              <el-option
                  v-for="item in dict.GeneralStatus"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="createTime">
            <el-date-picker v-model="form.createTime" type="datetime" value-format="YYYY-MM-DD HH:mm:ss" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <template v-slot:footer class="dialog-footer">
          <el-button @click="dialog.visible = false">关闭</el-button>
          <el-button type="primary" :loading="dialog.status === DIALOG_STATUS.PROCESSING" @click="submitCE">确认
          </el-button>
        </template>
      </el-dialog>
  </div>
</template>

<script>
import useCrud from "@crud/useCrud"
import udOperation from "@crud/UD.operation"
import rrOperation from "@crud/RR.operation"
import crudOperation from "@crud/CRUD.operation"
import pagination from "@crud/Pagination"
import api from '@/api/demo'

export default {
  name: 'Demo',
  components: { pagination, crudOperation, rrOperation, udOperation },
  dicts: ['GeneralStatus'],

  setup() {
    return {
      permission: {
        create: ['demo:save'],
        edit: ['demo:update'],
        remove: ['demo:remove']
      },
      ...useCrud({
        title: 'demo',
        defaultForm: {id: null, title: null, categoryId: null, link: null, status: null, createTime: null, updateTime: null, uni: null},
        methods: {...api}
      })
    }
  },

  data() {
    return {
      rules: {
        title: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        link: [
          { required: true, message: '链接地址不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'title', display_name: '名称' },
        { key: 'categoryId', display_name: '分类id' },
        { key: 'link', display_name: '链接地址' }
      ]
    }
  }
}
</script>

<style scoped>

</style>
